#pragma once
#ifndef __MESHPART_H__
#define __MESHPART_H__

#include "Utility.h"

#include "../util/PreDeclare.h"

#include "MeshPartInfo.h"

namespace WindGE
{
	class WIND_CORE_API MeshPart
	{
	public:
		MeshPart();
		~MeshPart();

		bool init_vertex_stream(const std::string& name, unsigned int stride, unsigned int count);
		bool reinit_vertex_stream(const std::string& name, unsigned int num);
		
		void add_vertex_stream(const std::string& name, void* vertBuff);
		void add_vertex_stream(const std::string& name, void* vertBuff, unsigned int num);

		void set_vertex_stream(const std::string& name, void* vertBuff, unsigned int offset);
		void set_vertex_stream(const std::string& name, void* vertBuff, unsigned int offset, unsigned int num);

		bool save(std::ostream& outFile);
		bool load(std::istream& inFile);

		void add(VertexStreamPtr vertexStream);
		void add(const VertexStream& vertexStream);

		bool find(const std::string& name, VertexStreamPtr& vs) const;
		void visit_stream_mapping(std::function<void (VertexStreamPair)> func) const;

		inline unsigned int stream_count() const { return stream_mapping_.size(); }

		inline void set_part_info(unsigned int vo, unsigned int vc, unsigned int io, unsigned int ic) {
			part_info_.set(vo, vc, io, ic);
		}
		inline void set_part_info(const MeshPartInfo& partInfo) { part_info_ = partInfo; }

		inline const MeshPartInfo&	part_info()		const { return part_info_; }
		inline unsigned int			vertex_count()	const { return part_info_.vertexCount; }
		inline unsigned int			index_count()	const { return part_info_.indexCount;  }

	private:
		MeshPartInfo		part_info_;
		VertexStreamMapping stream_mapping_;
	};

}//end namespace WindGE

#endif // !__MESHPART_H__


